﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F_MODEL;
using System.Data;
using System.Data.SqlClient;

namespace F_DAL
{

    /// <summary>
    /// 我的钱包相关数据操作  （我的钱包、 提现、交易明细、优惠券）
    /// </summary>
    public class MyWallet
    {
        /// <summary>
        /// 交易明细 -- 所有数据
        /// </summary>
        /// <returns></returns>
        public List<TransactionDetail> Trans_show(int userid)
        {
            SqlParameter[] sql ={
                               new SqlParameter("@Userid",SqlDbType.Int)
                               };
            sql[0].Value = userid;
          
            List<TransactionDetail> list = new List<TransactionDetail>();
            SqlDataReader read = DbHelperSQL.RunProcedure("TransactionDetail_All", sql);
            while (read.Read())
            {
                TransactionDetail mod = new TransactionDetail();
                mod.transactionIsDel = Convert.ToInt32(read["transactionIsDel"].ToString());
                mod.transactionTimeSpan = Convert.ToDateTime(read["transactionTimeSpan"].ToString());
                mod.isPrivileged =Convert.ToInt32(read["isPrivileged"].ToString());
                mod.transactionId = read["transactionId"].ToString();
                mod.transactionMoney =Convert.ToDecimal(read["transactionMoney"].ToString());
                mod.transactionTime =Convert.ToDateTime(read["transactionTime"].ToString());
                mod.transactionType =Convert.ToInt32(read["transactionType"].ToString());
                mod.userId = Convert.ToInt32(read["userId"]);
                list.Add(mod);
            }
            return list;
        }

        /// <summary>
        /// 优惠券数据
        /// </summary>
        /// <returns></returns>
        public List<Coupons> Coupons_show(int userid)
        {
            SqlParameter[] sql ={
                               new SqlParameter("@Userid",SqlDbType.Int)
                               };
            sql[0].Value = userid;
            List<Coupons> list = new List<Coupons>();
            SqlDataReader read = DbHelperSQL.RunProcedure("Coupons_All", sql);
            while (read.Read())
            {
                Coupons mod = new Coupons();
                mod.couponsEndTime = read["couponsEndTime"].ToString();
                mod.couponsId = Convert.ToInt32(read["couponsId"].ToString());
                mod.couponsIsDel = Convert.ToInt32(read["couponsIsDel"].ToString());
                mod.couponsTimeSpan = read["couponsTimeSpan"].ToString();
                mod.couponsType = Convert.ToInt32(read["couponsType"].ToString());
                mod.couponsUseTime = read["couponsUseTime"].ToString();
                mod.couponsValue = Convert.ToInt32(read["couponsValue"].ToString());
                mod.userId = Convert.ToInt32(read["userId"].ToString());
                list.Add(mod);
            }
            return list;
        }
        /// <summary>
        /// 提现流程
        /// </summary>
        /// <param name="Trans"></param>
        /// <returns></returns>
        public bool Tixian(TransactionDetail Trans)
        {
            SqlParameter[] sql ={
                              new  SqlParameter("@price",SqlDbType.Decimal),
                              new  SqlParameter("@transactionId",SqlDbType.VarChar),
                              new  SqlParameter("@transactionType",SqlDbType.Int),
                              new  SqlParameter("@transactionTime",SqlDbType.DateTime),
                              new  SqlParameter("@isPrivileged",SqlDbType.Int),
                              new  SqlParameter("@transactionIsDel",SqlDbType.Int),
                              new  SqlParameter("@transactionTimeSpan",SqlDbType.DateTime),
                              new  SqlParameter("@userId",SqlDbType.Int),
                              };
            sql[0].Value = Trans.transactionMoney;
            sql[1].Value = Trans.transactionId;
            sql[2].Value = Trans.transactionType;
            sql[3].Value = Trans.transactionTime;
            sql[4].Value = Trans.isPrivileged;
            sql[5].Value = Trans.transactionIsDel;
            sql[6].Value = Trans.transactionTimeSpan;
            sql[7].Value = Trans.userId;
            return DbHelperSQL.RunProcedureReturnBool("Shiwu", sql);
        }
    }
}